﻿namespace Localization
{
    using System;
    using System.Windows.Markup;

    public class TranslateExtension : MarkupExtension
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TranslateExtension"/> class.
        /// </summary>
        public TranslateExtension()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TranslateExtension"/> class.
        /// </summary>
        /// <param name="word">The word.</param>
        public TranslateExtension(string word)
            : this()
        {
            this.Word = word;
        }

        /// <summary>
        /// Gets or sets the word to translate.
        /// </summary>
        /// <value>The word to translate.</value>
        public string Word { get; set; }

        /// <summary>
        /// When implemented in a derived class, returns an object that is set as the value of the target property for this markup extension.
        /// </summary>
        /// <param name="serviceProvider">Object that can provide services for the markup extension.</param>
        /// <returns>
        /// The object value to set on the property where the extension is applied.
        /// </returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return LanguageContainer.Instance[this.Word];
        }
    }
}